<layout name="Layout/layout" />
<div class="row">
	<div class="col-lg-12">
		<h1 class="page-header">IP</h1>
	</div>
	<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
			<div class="panel-heading">
				IP池
			</div>
			<!-- /.panel-heading -->
			<div class="panel-body">
				<div class="dataTable_wrapper">
					<table class="table table-striped table-bordered table-hover" id="dataTables-example">
						<thead>
							<tr>
								<th>ID</th>
								<th>IP地址</th>
								<th>备注</th>
								<th>可用？</th>
								<th>修改</th>
								<th>删除</th>
							</tr>
						</thead>
						<tbody>
							<?php 
								foreach($iplist as $k=>$v){
									$trclass = '';
									if($k%2==0){
										$trclass = 'odd';
									}else{
										$trclass = 'even';
									}
									?>
									<tr class="{$trclass}">
										<td>{$v['id']}</td>
										<td>{$v['name']}</td>
										<td>{$v['title']}</td>
										<td><div class="switch" data-on-label="启用中" data-off-label="禁用中"><input name="isopen" type="checkbox" /></div></td>
										<td><a href="{:U("Admin/Ip/updateIp",array("ip_id"=>$v['id']))}">修改</a></td>
										<td><a href="{:U("Admin/Ip/deleteIpHandle",array("ip_id"=>$v['id']))}" id="delete_link" onclick="delete_confirm()">删除</a></td>
									</tr>
									<?php 
								}
							?>
						</tbody>
					</table>
				</div>

			</div>
			<!-- /.panel-body -->
		</div>
		<!-- /.panel -->
	</div>
	<!-- /.col-lg-12 -->
</div>
<script>
	window.onload = function(){
		$.fn.bootstrapSwitch.defaults.onText = '启用中';
		$.fn.bootstrapSwitch.defaults.offText = '禁用中';
		$.fn.bootstrapSwitch.defaults.onColor = 'success';
		$.fn.bootstrapSwitch.defaults.offColor = 'warning';
		$("[name=isopen]").bootstrapSwitch();
		$('input[name="isopen"]').on('switchChange.bootstrapSwitch', function(event, state) {
		 	var id = $(this).parent().parent().parent().parent().prevAll().last().text();
			$.post("{:U('Admin/Ip/setStatus')}",{
				status: state,
				id: id
			},
			function(data, status){
				console.log(data);
			});
		});
	}
</script>